package co.unal.visor.controller;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

import co.unal.visor.model.Image;
import co.unal.visor.model.ImageReader;
import co.unal.visor.model.ImageSource;
import co.unal.visor.model.interfaces.IFilter;

public class FilterManager {
	
	ImageSource imageSource;
	File sourceFile;
	

	private ArrayList<IFilter> filters;
	
	public FilterManager(File filename){
		filters = new ArrayList<IFilter>();
		this.sourceFile = filename;
	}
	
	public FilterManager(){
		filters = new ArrayList<IFilter>();
	}
	
	public void register(IFilter filter){
		filters.add(filter);
	}
	
	public Image execute(){
		try {
			imageSource = new ImageSource(sourceFile.getPath());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		Image img = imageSource.produce();
		/*
		 * esto no esta controlado....
		 * si mando un proceso...
		 * digamos de histograma que era lo q estaba haciewndo
		 * iba a greyscalefilter
		 * y lo ejecutaba sinque yo le dijera
		 * y se me tardaba un resto
		 * esto no esta controlado :P
		 * 
		 */
		for(IFilter filter : filters){
			img = filter.process(img);
		}
		return img;
	}

	public File getSourceFile() {
		return sourceFile;
	}
	
	public void setSourceFile(File sourceFile) {
		this.sourceFile = sourceFile;
	}

}
